package com.lishe.lishe.lishe.module.me.http;

import android.content.Context;
import android.util.Log;

import com.lishe.lishe.asynchttp.HttpUtils;
import com.lishe.lishe.asynchttp.LSWebHelper;
import com.lishe.lishe.lishe.common.Globals;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;

import java.util.HashMap;

/**
 * Created by zhcasecom on 2017/8/15.
 */

public class HttpUserCenter {
    private static final String USER_CENTER = "Home/User/";
    private static final String CMS = "Home/Cms/";

    /**
     * 获取登入后获得的token
     *
     * @param params
     * @return
     */
    public static RequestParams getToken(RequestParams params) {
        if (params == null) {
            params = new RequestParams();
        }
        String token = Globals.getToken();
        if (token != null)
            params.add("token", token);
        return params;
    }

    /**
     * 个人中心信息获取
     *
     * @param params
     * @throws Exception
     */
    public static void getUserInfo(RequestParams params, ResponseHandlerInterface response) {
        params = getToken(params);
        HttpUtils.post(Globals.LISHE_URL + USER_CENTER + "userCenter", params, response);
    }

    /**
     * 个人中心信息获取
     *
     * @param params
     * @throws Exception
     */
    public static void getUserInfoMain(HashMap params, LSWebHelper.WebCallBack response) {
        //params = getToken(params);
        LSWebHelper.getInstance().postAsynUseToken("Home/UserV230/userCenter", params, response);
    }

    /**
     * 福利积分获取
     *
     * @param params
     * @param response
     * @throws Exception
     */
    public static void getBalance(HashMap params, LSWebHelper.WebCallBack response) throws Exception {
//        params = getToken(params);
//        HttpUtils.post(Globals.LISHE_URL + USER_CENTER + "assets", params, response);
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "getUserIntegral", params, response);
        Log.e("TEST", "params" + params);
    }

    /**
     * 优惠券
     *
     * @param params
     * @param response
     * @throws Exception
     */
    public static void getLisheMoney(HashMap params, LSWebHelper.WebCallBack response) throws Exception {
//        params = getToken(params);
//        HttpUtils.post(Globals.LISHE_URL + USER_CENTER + "lisheMoney", params, response);
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "lisheMoney", params, response);
        Log.e("TEST", "params" + params);

    }

    /**
     * 礼舍币
     *
     * @param params
     * @param response
     * @throws Exception
     */
    public static void getCoupons(HashMap params, LSWebHelper.WebCallBack response) throws Exception {
//        params = getToken(params);
//        HttpUtils.post(Globals.LISHE_URL+ USER_CENTER + "coupons", params, response);
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "coupons", params, response);
        Log.e("TEST", "params" + params);
    }

//    /**
//     * 意见反馈
//     *
//     * @param params
//     * @param response
//     * @throws Exception
//     */
//    public static void postSuggestData(HashMap params, LSWebHelper.WebUpLoadFileCallBack response) throws Exception {
////        params = getToken(params);
////        HttpUtils.post(Globals.LISHE_URL + USER_CENTER + "feedback", params, response);
//        LSWebHelper.getInstance().postAsynUploadFileUseToken(USER_CENTER + "feedback", params, response);
//        Log.e("TEST", "params" + params);
//    }

    /**
     * 意见反馈
     *
     * @param params
     * @param response
     * @throws Exception
     */
    public static void postSuggestData(Context ctx,HashMap params,HashMap fileParams, LSWebHelper.WebUpLoadFileCallBack response) throws Exception {
//        params = getToken(params);
//        HttpUtils.post(Globals.LISHE_URL + USER_CENTER + "feedback", params, response);
        LSWebHelper.getInstance().postSynUploadFileUseToken(ctx,USER_CENTER + "feedback", params,fileParams, response);
        Log.e("TEST", "params" + params);
    }

    /**
     * 我的地址
     *
     * @param params
     * @param response
     */
    public static void getAddressList(HashMap params, LSWebHelper.WebCallBack response) {
//        params = getToken(params);
//        HttpUtils.post(Globals.LISHE_URL + USER_CENTER + "addrList", params, response);
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "addrList", params, response);
        Log.e("TEST", "params" + params);
    }

    public static void changeDefaultAddr(HashMap params, LSWebHelper.WebCallBack response) {
//        params = getToken(params);
//        HttpUtils.post(Globals.LISHE_URL + USER_CENTER + "modifyDefAddr", params, response);
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "modifyDefAddr", params, response);
        Log.e("TEST", "params" + params);
    }

    public static void getSetUserInfo(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "getUserInfo", params, response);
        Log.e("TEST", "params" + params);
    }

    public static void getUserMobile(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "getUserMobile", params, response);
    }

    public static void setNickName(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "updateUsernickName", params, response);
    }

    public static void updateBirth(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "updateUserBirthday", params, response);
    }

    public static void getAddressInfo(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().getAsynUseToken(USER_CENTER + "editAddress", params, response);
    }

    /**
     * 获取地址级联
     *
     * @param params
     * @param response
     */
    public static void getAreaById(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().getAsyn(USER_CENTER + "getSiteList", params, response);
    }

    public static void deleteAddress(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "deleteAddr", params, response);
    }

    public static void saveAddress(HashMap params, LSWebHelper.WebCallBack response) {
        LSWebHelper.getInstance().postAsynUseToken(USER_CENTER + "addAddress", params, response);
    }

    /**
     * 鉴权:设置支付密码 获取验证短信
     *
     * @param ctx
     * @param params
     * @param callBack
     */
    public static void doGetPayPassCheckCodeInSetting(final Context ctx, HashMap<String, Object> params, final LSWebHelper.WebCallBack callBack) {
        String relativeUrl = CMS + "sendAmendPayMsgVerifyCode";

        LSWebHelper.getInstance().postAsynUseToken(relativeUrl, params, callBack);
    }

    /**
     * 鉴权:设置支付密码 密码设置（最后一步）
     *
     * @param ctx
     * @param params
     * @param callBack
     */
    public static void doSetPayPasswordInSetting(final Context ctx, HashMap<String, Object> params, final LSWebHelper.WebCallBack callBack) {
        String relativeUrl = CMS + "setPayPassword";

        LSWebHelper.getInstance().postAsynUseToken(relativeUrl, params, callBack);
    }

    /**
     * 鉴权:设置支付密码 比对验证码
     *
     * @param ctx
     * @param params
     * @param callBack
     */
    public static void doCheckPayMsgVerifyCodeInSetting(final Context ctx, HashMap<String, Object> params, final LSWebHelper.WebCallBack callBack) {
        String relativeUrl = CMS + "checkAmendPayMsgVerifyCode";

        LSWebHelper.getInstance().postAsynUseToken(relativeUrl, params, callBack);
    }

    /**
     * 鉴权:找回密码 获取验证短信
     *
     * @param ctx
     * @param params
     * @param callBack
     */
    public static void doGetLoginPassCheckCode(final Context ctx, HashMap<String, Object> params, final LSWebHelper.WebCallBack callBack) {
        String relativeUrl = CMS + "sendAmendMsgVerifyCode";

        LSWebHelper.getInstance().postAsynUseToken(relativeUrl, params, callBack);
    }

    /**
     * 鉴权:找回密码 比对验证码
     *
     * @param ctx
     * @param params
     * @param callBack
     */
    public static void doCheckRetrievedMsgVerifyCode(final Context ctx, HashMap<String, Object> params, final LSWebHelper.WebCallBack callBack) {
        String relativeUrl = CMS + "checkAmendMsgVerifyCode";

        LSWebHelper.getInstance().postAsynUseToken(relativeUrl, params, callBack);
    }

    /**
     * 鉴权:找回密码 密码设置（最后一步）
     *
     * @param ctx
     * @param params
     * @param callBack
     */
    public static void doSetLoginPassword(final Context ctx, HashMap<String, Object> params, final LSWebHelper.WebCallBack callBack) {
        String relativeUrl = CMS + "setLoginPassword";

        LSWebHelper.getInstance().postAsynUseToken(relativeUrl, params, callBack);
    }


}
